home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#03 (Aug85-Sep85)
/
Pascal
/
Pascal Vol. 1 #10
/
Get_Fortune
< prev
next >
Wrap
Text File
|
1985-07-13
|
6KB
|
264 lines
program Apple_talk_Access;{ by Alan Wootton 7/85 }
type
ptr = ^integer;
strptr = ^str255;
Bsplit = packed array[0..1] of char;
AddrBlockRec = record
aNet : integer;
aNode_aSocket : Bsplit
end;
BDSElement = record
buffSize : integer;
buffPtr : ptr;
datasize : integer;
userbytes : longint
end;
BDSType = array[0..7] of BDSElement;
NtTuple = record
NetworkNumber : integer;
NodeID_SocketNumber : Bsplit;
none_ObjectName : Bsplit;
entityname : array[0..42] of integer;
end;
NamesTableEntry = record
nextEntry : ^NamesTableEntry;
NetworkNumber : integer;
NodeID_SocketNumber : Bsplit;
none_ObjectName : Bsplit;
entityname : array[0..42] of integer;
end;
{ Parameter Block information, heavily modified for Appletalk}
ParamBlkPtr = ^ParamBlockRec;
ParamBlockRec = record{ data structure for control call }
qLink : Ptr;
qType : integer;
ioTrap : integer;
ioCmdAddr : ptr;
ioCompletion : ptr;
reqTid : integer;
ioNamePtr : ^str255;{ also UserData }
ioVrefnum : integer;
ioRefNum : integer;
csCode : integer;
case integer of
0 : (
ATPSocket_ATPFlags : Bsplit;
AddrBlock : AddrBlockrec;
ReqLength : integer;
Reqpointer : ptr;
BDSpointer : ^BDSelement;
numofBuffs_timeoutVal : Bsplit;
numofResps_retrycount : Bsplit
);
1 : (
curRBitmap_ATPflags : Bsplit;
dummy1 : longint;
confirmAddr : ptr;
dummy2 : array[0..2] of integer;
bitMap_BDSsize : Bsplit;
transID : integer
);
2 : (
interval_count : Bsplit;
ntQElPtr : ^namesTableEntry;
verifyFlag_none : Bsplit;
dummy3 : integer;
newSocket_none : Bsplit;
dummy4 : longint;
rspNum_none : Bsplit
);
3 : (
dummy5 : integer;
entityPtr : ^char;{ actually three packed str's }
retBuffPtr : ptr;
retbuffsize : integer;
maxtoget : integer;
numgotten : integer
)
end;
{ common OS trap code, could be done with 'Generic' call }
function filecall (Pb : ParamBlkPtr;
trap : integer) : integer;{ OSError }
var
d0, a0 : longint;
access : array[0..12] of integer;
begin
stuffHex(@access, '2848548C41FA000C309F245F265F20522013FFFF224826804ED4');
a0 := ord(pb);
inlineP($4E75, @d0, @a0, trap, @access);
filecall := loword(d0);
end;
procedure pack3str (strP : strptr;
s1, s2, s3 : str255);
begin
strP^ := s1;
strP := pointer(ord(strP) + length(strP^) + 1);
strP^ := s2;
strP := pointer(ord(strP) + length(strP^) + 1);
strP^ := s3;
end;
function ATPLoad : integer;{ OSError }
type
r = record
use : char;
end;
var
pblock : ParamBlockRec;
Tstr : str255;
PortBUseP : ^r;
SPConfigP : ^char;
err : integer;
begin
pBlock.ioNamePtr := @Tstr;
pBlock.dummy5 := 0;{ ioPermssn }
PortBUseP := pointer($291);
SPConfigP := pointer($1FB);
with PortBUseP^ do
begin
writeln(' PortBuse is ', ord(use));
if ord(use) > 127 then
begin
err := -98;{ assume portNotCf }
if (ord(SPConfigP^) mod 16) < 2 then
begin
Tstr := '.MPP';
err := filecall(@pBlock, $A000);{ open }
end
end
else if (ord(use) mod 16) <> 1 then
err := -97;{ PortInUse }
if (not odd((ord(use) div 16))) and (err = 0) then
begin
Tstr := '.ATP';
err := filecall(@pBlock, $A000);{ open }
end;
end;{ of with }
ATPLoad := err;
end;{ of function }
function ATPcall (Pb : ParamBlkPtr) : integer;
begin
Pb^.ioRefNum := -11;
ATPcall := filecall(Pb, $A004);{ control }
end;
function OpenATPSkt (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 254;
OpenATPSkt := ATPcall(Pb);
end;
function CloseATPSkt (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 250;
CloseATPSkt := ATPcall(Pb);
end;
function SendRequest (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 255;
SendRequest := ATPcall(Pb);
end;
function GetRequest (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 253;
GetRequest := ATPcall(Pb);
end;
function SendResponse (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 252;
SendResponse := ATPcall(Pb);
end;
function MPPcall (Pb : ParamBlkPtr) : integer;
begin
Pb^.ioRefNum := -10;
MPPcall := filecall(Pb, $A004);{ control }
end;
function RegisterName (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 253;
RegisterName := MPPcall(Pb);
end;
function LookupName (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 251;
LookupName := MPPcall(Pb);
end;
function RemoveName (Pb : ParamBlkPtr) : integer;
begin
Pb^.csCode := 252;
RemoveName := MPPcall(Pb);
end;
procedure Get_Fortune;
var
Nblock, Sblock : ParamBlockRec;
myNtable : NamesTableEntry;
myTuple : ntTuple;
myBDS : BDStype;
strP : strptr;
err : integer;
reply : str255;
begin
if ATPLoad = 0 then
begin
with Nblock do
begin
interval_count[0] := chr(1);
interval_count[1] := chr(32);
strP := pointer(ord(@myNtable.none_ObjectName[1]));
pack3str(strP, '=', 'Dial-A-Fortune', '=');
entityPtr := pointer(ord(@myNtable.none_ObjectName[1]));
retBuffptr := pointer(ord(@myTuple));
retBuffsize := sizeof(myTuple);
maxToGet := 1;{ if larger use array of tuples}
err := LookupName(@Nblock);
writeln('lookup err', err);
end;{ of with Nblock }
if err = 0 then
with Sblock do
with myTuple do
begin
ATPsocket_ATPFlags[1] := chr(32);{atpXObit}
addrBlock.aNet := networkNumber;
addrBlock.aNode_Asocket[0] := nodeID_SocketNumber[0];
addrBlock.aNode_Asocket[1] := nodeID_SocketNumber[1];
reqLength := 0;{no request data}
reqPointer := nil;
bdsPointer := @myBDS;
numOfBuffs_timeoutval[0] := chr(1);{buffers}
numOfBuffs_timeoutval[1] := chr(2);{sec until retry}
numOfResps_retryCount[1] := chr(3);{retry until quit}
myBDS[0].buffsize := 256;
myBDS[0].buffPtr := pointer(ord(@reply));
err := sendRequest(@Sblock);
writeln('request err', err);
writeln('fortune returned is - ', reply);
end;
end
else
writeln('Appletalk open error ', ATPLoad);
end;
begin { main main main main main main }
showtext;
Get_Fortune;
end.